//package work.rightAnswer;
//
//import java.util.Stack;
//
//class max_square84 {
//    public int largestRectangleArea(int[] heights) {
//        Stack<Integer> stack = new Stack<>();
//        int maxSquare = Integer.MIN_VALUE;
//        for (int i = 0; i < heights.length; i++) {
//            if(stack.isEmpty()){
//                stack.push(i);
//                continue;
//            }
//            Integer peek = stack.peek();
//            if(heights[peek]<=heights[i]){
//                stack.push(i);
//            }else {
//                while (!stack.isEmpty()&&heights[stack.peek()]>heights[i]){
//                    Integer pop = stack.pop();
//                    int height = heights[pop];
//                    int width = i - 1 - (stack.isEmpty()?-1:stack.peek());
//                    maxSquare = height*width>maxSquare?height*width:maxSquare;
//                }
//                stack.push(i);
//            }
//
//        }
//        int length = heights.length;
//        while (!stack.isEmpty()){
//            Integer pop = stack.pop();
//            int height = heights[pop];
//            int width = length - 1 - (stack.isEmpty()?-1:stack.peek());
//            maxSquare = height*width>maxSquare?height*width:maxSquare;
//        }
//        return maxSquare;
//    }
//}